﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace CodeFarmer.Core.Data
{
    /// <summary>
    ///
    /// </summary>
    public class SqlParamHelper
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="ParamName"></param>
        /// <param name="DbType"></param>
        /// <param name="Size"></param>
        /// <param name="Direction"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static SqlParameter MakeParam(string ParamName, SqlDbType DbType, int Size, ParameterDirection Direction, object Value)
        {
            SqlParameter parameter;
            if (Size > 0)
            {
                parameter = new SqlParameter(ParamName, DbType, Size);
            }
            else
            {
                parameter = new SqlParameter(ParamName, DbType);
            }
            parameter.Direction = Direction;
            if (Direction != ParameterDirection.Output || Value != null)
            {
                parameter.Value = Value;
            }
            return parameter;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ParamName"></param>
        /// <param name="DbType"></param>
        /// <param name="Size"></param>
        /// <returns></returns>
        public static SqlParameter MakeOutParam(string ParamName, SqlDbType DbType, int Size)
        {
            return SqlParamHelper.MakeParam(ParamName, DbType, Size, ParameterDirection.Output, null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ParamName"></param>
        /// <param name="DbType"></param>
        /// <param name="Size"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static SqlParameter MakeInParam(string ParamName, SqlDbType DbType, int Size, object Value)
        {
            return SqlParamHelper.MakeParam(ParamName, DbType, Size, ParameterDirection.Input, Value);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ParamName"></param>
        /// <param name="DbType"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static SqlParameter MakeInParam(string ParamName, SqlDbType DbType, object Value)
        {
            return SqlParamHelper.MakeParam(ParamName, DbType, 255, ParameterDirection.Input, Value);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ParamName"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static SqlParameter MakeInParam(string ParamName, object Value)
        {
            return new SqlParameter(ParamName, Value);
        }
    }
}